#include <hidef.h> /* for EnableInterrupts macro */
#include "Headers/derivative.h" /* include peripheral declarations */
#define output  1
#define input   0
#define on      1
#define off     0
  
#define cero    1
#define uno     2
#define dos     4
#define tres    8
#define cuatro  16
#define cinco   32
#define seis    64
#define siete   128
/**** SPI pines *********/                            
#define M_RST   PTDD_PTDD3
#define ATTN    PTDD_PTDD0
#define RXTXEN  PTDD_PTDD1
#define CE      PTED_PTED2
/************************/

// this are the defined register to the moden
//-----------------------------------------//
#define RESET           0x00
#define RX_Pkt_RAM      0x01
#define TX_Pkt_RAM      0x02
#define TX_Pkt_Ctl      0x03
#define CCA_Thresh      0x04
#define IRQ_Mask        0x05
#define Control_A       0x06
#define Control_B       0x07
#define PA_Enable       0x08
#define Control_C       0x09
#define CLKO_Ctl        0x0A
#define GPIO_Dir        0x0B
#define GPIO_Data_Uot   0x0C
#define LO1_Int_Div     0x0F
#define LO1_Num         0x10
#define PA_Lvl          0x12
#define Tmr_Cmp1_A      0x1B
#define Tmr_Cmp1_B      0x1C
#define Tmr_Cmp2_A      0x1D
#define Tmr_Cmp2_B      0x1E
#define Tmr_Cmp3_A      0x1F
#define Tmr_Cmp3_B      0x20
#define Tmr_Cmp4_A      0x21
#define Tmr_Cmp4_B      0x22
#define TC2_Prime       0x23
#define IRQ_Status      0x24
#define RST_Ind         0x25
#define Current_Time_A  0x26
#define Current_Time_B  0x27
#define GPIO_Data_In    0x28
#define Chip_Id         0x2C
#define RX_Status       0x2D
#define Timestamp_A     0x2E
#define Timestamp_B     0x2F
#define BER_Enable      0x30
#define PSM_Mode        0x31   
#define Reserved        0x34
//-----------------------------------------//
//-----------------------------------------//

//---------CONTROL_A-----------------------//
//-----------------------------------------//
#define Control_A_tx_strm       0x1000
#define Control_A_rx_strm       0x0800
#define Control_A_cca_mask      0x0400
#define Control_A_tx_send_mask  0x0200
#define Control_A_rx_rcvd_mask  0x0100
#define Control_A_tmr_trig_en   0x0080
#define Control_A_cca_type_clear_chanel 0x0010
#define Control_A_cca_type_energy_detect 0x0020
#define Control_A_xcvr_seq_Idle 0xFFFC //this must be programed with an and
#define Control_A_xcvr_seq_CCA  0x0001
#define Control_A_xcvr_seq_Rx   0x0002
#define Control_A_xcvr_seq_Tx   0x0003
//-----------------------------------------//
//-----------------------------------------//

//---------CONTROL_B-----------------------//
//-----------------------------------------//
#define Control_B_tmr_load        0x8000
#define Control_B_ct_bias_en      0x4000
#define Control_B_ct_bias_inv     0x2000
#define Control_B_RF_switch_mode  0x1000
#define Control_B_miso_hiz_en     0x0800
#define Control_B_clko_doze_en    0x0200
#define Control_B_tx_done_mask    0x0080
#define Control_B_rx_done_mask    0x0040
#define Control_B_use_strm_mode   0x0020
#define Control_B_hib_en          0x0002
#define Control_B_doze_en         0x0001
//-----------------------------------------//
//-----------------------------------------//

//---------CONTROL_C-----------------------//
//-----------------------------------------//
#define Control_C_gpio_alt_en     0x0080
#define Control_C_clko_en         0x0020
#define Control_C_tmr_prescale0   0x0000
#define Control_C_tmr_prescale1   0x0001
#define Control_C_tmr_prescale2   0x0002
#define Control_C_tmr_prescale3   0x0003
#define Control_C_tmr_prescale4   0x0004
#define Control_C_tmr_prescale5   0x0005
#define Control_C_tmr_prescale6   0x0006
#define Control_C_tmr_prescale7   0x0007
//-----------------------------------------//
//-----------------------------------------//

//-----------232---------------------------//
//-----------------------------------------//
#define Baud300     3334
#define Baud1200    833
#define Baud2400    417
#define Baud4800    208
#define Baud9600    104
#define Baud19200   52
#define Baud38400   26
#define Baud57600   17 // use only with a external reference clock
#define Baud115200  8  // use only with a external reference clock
#define Baud230400  4  // use only with a external reference clock
#define Baud460800  2  // use only with a external reference clock
#define Baud921600  1  // use only with a external reference clock

#define Single_wire         0x80
#define Normal_wire         0
#define clock_freez         0x40
#define Receiver_soucer     0x20
#define nine_bits           0x10
#define Adress_mark_wakeup  0x08
#define ILT                 0x04
#define parity              0x02
#define Odd_parity          0x01
//-----------------------------------------//
//-----------------------------------------//

#define bit0    0x0001
#define bit1    0x0002
#define bit2    0x0004
#define bit3    0x0008
#define bit4    0x0010
#define bit5    0x0020
#define bit6    0x0040
#define bit7    0x0080
#define bit8    0x0100
#define bit9    0x0200
#define bit10   0x0400
#define bit11   0x0800
#define bit12   0x1000
#define bit13   0x2000
#define bit14   0x4000
#define bit15   0x8000
    
#define sw1   PTAD_PTAD2
#define sw2   PTAD_PTAD3
#define sw3   PTAD_PTAD4
#define sw4   PTAD_PTAD5

#define ld1   PTDD_PTDD4
#define ld2   PTDD_PTDD5
#define ld3   PTDD_PTDD6
#define ld4   PTDD_PTDD7

#define ADDR_SLAVE   0xA4